package cn.byapps.attendance.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import cn.byapps.attendance.dao.JobDao;
import cn.byapps.attendance.entity.Job;
import cn.byapps.attendance.service.JobService;
import cn.byapps.attendance.util.DataTablesResult;
import core.service.impl.BaseServiceImpl;

@Service
public class JobServiceImpl extends BaseServiceImpl<Job> implements JobService {

	@Resource
	private JobDao jobDao;

	@Override
	public List<Job> listAll() {
		Map<String, Object> maps = new HashMap<String, Object>();
		maps.put("flag",true);
		return jobDao.findAll(maps);
	}

	@Override
	public DataTablesResult<Job> getData(Integer draw,Integer pos,Integer rows) {
		DataTablesResult<Job> ads = new DataTablesResult<Job>();
		ads.setDraw(draw);
		ads.setData(jobDao.find(pos, rows));
		long total = jobDao.count();
		ads.setRecordsFiltered(total);
		ads.setRecordsTotal(total);
		return ads;
	}

	@Override
	public Job updateName(Job entity) {
		Job ad  = jobDao.get(entity.getId());
		ad.setName(entity.getName());
		return ad;
	}

	@Override
	public Job updateFlag(Integer id) {
		Job ad  = jobDao.get(id);
		ad.setFlag(!ad.getFlag());
		return ad;
	}

}
